package com.gfxy.common.model;

/**
 * @author: lijixin 2019-05-30
 */
public enum StateEnum {
    VALID(0,"有效"),INVALID(1,"无效");

    private final int index;
    private final String name;
    StateEnum(int index, String name) {
        this.index = index;
        this.name = name;
    }

    public StateEnum getStateEnumByIndex(int index){
        StateEnum result = null;

        for(StateEnum stateEnum : StateEnum.values()){
            if(stateEnum.index == index){
                result = stateEnum;
                break;
            }
        }

        if(result == null){
            throw new IllegalArgumentException("错误的枚举index值[" + index + "], 无法找到对应的枚举");
        } else {
            return result;
        }
    }

    public int getIndex() {
        return index;
    }

    public String getName() {
        return name;
    }
}
